import grails.util.Environment
import com.rideshare.*;
class BootStrap {

    def init = { servletContext ->
      
      switch(Environment.current) {
        
        case Environment.DEVELOPMENT:
        case Environment.PRODUCTION:
        
        def bus 
        def bike 
        def carpool;
        
        if (!CommuteMode.findByModeName("Bus")) {
            bus = new CommuteMode(modeName:"Bus",modeDescription:"This mode entails taking a private or public bus / rail trasportation to and from work.").save()
            bike = new CommuteMode(modeName:"Bike",modeDescription:"Riding your bike to and from work.").save()
            carpool = new CommuteMode(modeName:"Carpool",modeDescription:"Travelling to and from work in car with more than 1 person.").save()
            
            println("${carpool.modeDescription}")
           
        }
        
       
        if(!User.findByFirstName('Nikhil')) {
          def nikhil = new User(firstName:'Nikhil',lastName:'almeida').save()
          def ragib = new User(firstName:'Ragib',lastName:'morshed').save()
          
          
          nikhil.addToRecords( new CommuteRecord(mode:carpool, user:nikhil).save())
          nikhil.addToRecords( new CommuteRecord(mode:carpool, user:nikhil).save())
          nikhil.addToRecords( new CommuteRecord(mode:carpool, user:nikhil).save())
          
          ragib.addToRecords( new CommuteRecord(mode:carpool, user:ragib).save())
          ragib.addToRecords( new CommuteRecord(mode:carpool, user:ragib).save())
        }
        def nikhil= User.findByFirstName("Nikhil")
        
        println("${ CommuteMode.list().size()}")
        println nikhil.records.size()
       break;
        }
    }
    def destroy = {
    }
}
